﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using YuFeng.Web.Extentions;

namespace YuFeng.Web.Controllers
{
    public class BaseController : Controller
    {
        protected ActionResult SuccessResult(string message, bool dismissable = false)
        {
            this.Success(message, dismissable);
            return View("Alert");
        }
        protected ActionResult InfoResult(string message, bool dismissable = false)
        {
            this.Information(message, dismissable);
            return View("Alert");
        }
        protected ActionResult WarningResult(string message, bool dismissable = false)
        {
            this.Warning(message, dismissable);
            return View("Alert");
        }
        protected ActionResult DangerResult(string message, bool dismissable = false)
        {
            this.Danger(message, dismissable);
            return View("Alert");
        }
        #region

        /// <summary>
        /// 返回错误消息
        /// </summary>
        /// <param name="errmsg"></param>        
        /// <returns></returns>
        protected JsonResult ErrorMsg(string errmsg)
        {
            return this.ErrorMsg<string>(errmsg, null);
        }

        /// <summary>
        /// 返回错误消息
        /// </summary>
        /// <param name="errmsg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        protected JsonResult ErrorMsg<T>(string errmsg, T data)
        {
            return Json(new
            {
                status = 0,
                errmsg = errmsg,
                data = data
            }, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 返回成功消息
        /// </summary>                
        /// <returns></returns>
        protected JsonResult SuccessMsg()
        {
            return this.SuccessMsg<string>(null);
        }

        /// <summary>
        /// 返回成功消息
        /// </summary>        
        /// <param name="data">返回的数据</param>
        /// <returns></returns>
        protected JsonResult SuccessMsg<T>(T data)
        {
            return Json(new
            {
                status = 1,
                errmsg = "ok",
                data = data
            }, JsonRequestBehavior.AllowGet);
        }
        #endregion
    }
}